-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Navigation: Add Post, Page, Category and Tag variations to Link #24670
Conversation
@shaunandrews: Does this flow look right to you? |
Size Change: +1.99 kB (0%) Total Size: 1.16 MB
ℹ️ View Unchanged
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is actually a surprisingly straightforward change, which is nice.
In terms of user experience, I think it may be confusing that there's an overlap between the block functionality. I wonder if we should limit 'Link' to just being external links, 'Page' to just being pages etc.
I personally don't expect to get other options when I add those blocks, especially the 'Link' block which gets suggestions for everything.
packages/block-editor/src/components/link-control/use-search-handler.js
Outdated
Show resolved
Hide resolved
I'll defer to @shaunandrews on this one 😀 |
Why does this have a hardcoded list of post types and taxonomies? |
b4a1023
to
d42766c
Compare
Adds Post, Page, Category and Tag variations to the Navigation Link block. Each variation sets the type attribute which in turn causes LinkControl to filter its results using the /wp/v2/search API's type and subtype params.
d42766c
to
13a44f8
Compare
This has some test failures I need to fix up. |
I started by implementing the most common Link variations: Page, Post, Category, Tag. You're probably right though that this should be dynamic so that we have a Link block variation for every (custom) post type and (custom) taxonomy. |
👍 Yeah I think that'd be a worthwhile change. Would also make sure any changes to the post type label are picked up. |
Very cool to see this; I like having a block variation for each post type — though I worry a little about how this scales. Does a site with 20+ post type's defined then list 20+ link variations? If so, is that a problem? I'd expect a Page Link block to only list pages in it's default suggests and search; and similar, a Post Link block would only show posts. The more general catchall Link block should still be able to do it all, allowing the display of any post type along with supporting general URL links. I tried creating some new icons that use the Navigation icon in an attempt to visually brand these blocks together, but I think using the existing, more generic icons might work just as good, it not better. The new icons can be found in the WP Design Library Figma: |
Yeah this can get annoying in Core currently. For example if you have a site with a lot of CPTs/Taxonomies and open the Menus screen you wind up with a bunch of meta boxes and the screen can get a bit unwieldy. You can hide them via Screen Options, and I think(?) only some are shown by default which can be really confusing for the user. Making it a variation, though, feels like it might be a somewhat better experience? Since you are first searching & selecting the type and then that visual noise goes away. |
- Display 'Create post' when inserting a Post Link. - Display 'Create page' when inserting a Link or a Page Link. - Only allow direct URL input when inserting a Link.
This is ready for a re-review. I rebased the PR to include #22600 and fixed all of the test failures. I added the basic icons to each variation per @shaunandrews's suggestion above. "Create page" will appear at the bottom of the Link and Page variations and "Create post" will appear at the bottom of the Post variation. No creation is possible in the Tag and Category variations. Linking to a user inputted URL is only possible in the Link variation.
I agree that a variation should be added for each custom post type and taxonomy, but I would like to do this later as it's a little bit tricky to implement. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code looks good and works like a charm!
} | ||
return createInterpolateElement( | ||
sprintf( format, searchTerm ), | ||
{ mark: <mark /> } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So nice 👍
Issue here: #24814 |
At second glance, I don't think we need to post_type label in the search results if its only listing a single post_type. |
Issue here: #24839 |
Closes #22919.
Requires #22600.Split out from #24613.Adds Post, Page, Category and Tag variations to the Navigation Link block. Each variation sets the
type
attribute which in turn causesLinkControl
to filter its results using the/wp/v2/search
endpoint'stype
andsubtype
params.This PR requires #22600 which adds the ability to search for categories and triages using the search endpoint. Do not merge this PR until #22600 is merged and this PR's base is updated.How to test